/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eu.easyedu.dictionary.gui;

import java.awt.Color;
import java.awt.Component;
import java.util.HashSet;
import java.util.Set;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author hlavki
 */
public class ColorTextCellRenderer extends DefaultTableCellRenderer {

    private static final long serialVersionUID = 1L;
    private int column;
    private Set<Integer> wrongRows;

    public ColorTextCellRenderer(int column) {
        this.column = column;
        wrongRows = new HashSet<Integer>();
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
            boolean hasFocus, int row, int column) {
        Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        if (wrongRows.contains(new Integer(row)) && column == column) {
            c.setForeground(Color.RED);
        } else {
            c.setForeground(Color.BLACK);
        }
        return c;
    }

    public void addWrongRow(Integer wrongRow) {
        wrongRows.add(wrongRow);
    }

    public void clear() {
        wrongRows.clear();
    }
}
